package com.itheima;

import org.junit.Test;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

public class Topic3 {

    public int lengthOfLongestSubstring(String s) {

//        char[] arr = s.toCharArray();
        int v = 0;
        int maxV = 1;
        if(s.length() == 0) return 0;
        List<Character> list = new ArrayList<Character>();

        int l = 0;
        int r = 0;

        while(r < s.length()) {
            char c = s.charAt(r);
            if(list.contains(c)) {
                if(maxV < r - l) {
                    maxV = r - l;
                }
                list.remove(list.indexOf(s.charAt(l)));
                l++;
            } else{
                list.add(c);
                r++;
                if(maxV < r - l) {
                    maxV = r - l;
                }
            }
        }

        System.out.println(maxV);
        return maxV;

    }

    @Test
    public void test() {
        lengthOfLongestSubstring("dadvadec");
    }
}
